
 
/**
 * 实体管理类,检查任务状态,,房间状态等,更新实体,
*/
import { EntityDB } from "./EntityDB";
import * as  Entity from "./Entitys"
import { AllEntityTypes,EntityType } from "./Entitys/Entity.interface";
// import profiler from "screeps-profiler";
 
export class EntityFactory
{
    protected static _entityclass= new Map<EntityType, any>();
    public static init()
    {
        // this.PlanManager = new AutoPlanManager();
         
        EntityFactory.registerclass("InnerMineEntity",Entity.InnerMineEntity);
        EntityFactory.registerclass("SpawnEntity",Entity.SpawnEntity);
        EntityFactory.registerclass("OutMineEntity",Entity.OutMineEntity);
        // EntityFactory.registerclass("ControllerEntity",Entity.ControllerEntity);
        EntityFactory.registerclass("LabEntity",Entity.LabEntity);
        EntityFactory.registerclass("CoreEntity",Entity.CoreEntity);
        EntityFactory.registerclass("TeamUpgrader",Entity.TeamUpgrader);
        EntityFactory.registerclass("TeamDefender",Entity.TeamDefender);
        EntityFactory.registerclass("MinerialEntity",Entity.MinerialEntity);
        EntityFactory.registerclass("OutMinerialEntity",Entity.OutMinerialEntity);
        EntityFactory.registerclass("Team2",Entity.Team2);
        EntityFactory.registerclass("Team4",Entity.Team4);
        EntityFactory.registerclass("Team9",Entity.Team9);
    }
    private static registerclass(type:EntityType,classtype:any)
    {
        this._entityclass.set(type,classtype);
        // profiler.registerClass(classtype,type)
    }



    public static  Create<T extends EntityType>(type:EntityType ,initializer:IEntityInitializer,entityDb:EntityDB):AllEntityTypes[T]
    {
        const ModuleEntityClass = this._entityclass.get(type);
        // global.Log.Info(`创建实体 ${type} 对象  ${JSON.stringify(initializer)}`);
        if(!ModuleEntityClass)
        {
            global.Log.Error(`找不到${type } 对应的 class 类`);
            
        }
        const module  = new (ModuleEntityClass as any)() as AllEntityTypes[T];
        module.initialize(entityDb,initializer as any);
        module.initAttributes();
        return module as AllEntityTypes[T];
    }

    public static  CreateModule<T extends EntityType,I extends IEntityInitializer=IEntityInitializer>(type:T ,initializer:I,entityDb:EntityDB):AllEntityTypes[T]
    {
        return this.Create(type,initializer, entityDb)
    }

}